home *** CD-ROM | disk | FTP | other *** search
Text File | 1992-03-26 | 58.8 KB | 2,370 lines | [TEXT/MPS ] |
- UNIT BLObject;
- {••••• Objects, plus a few utility routines •••••}
-
- INTERFACE
-
- USES Memtypes,QuickDraw,OSIntf,ToolIntf,
- PackIntf,FixMath,ObjIntf;
-
- CONST menuCount = 5;
- ovalSize = 16; {For “FrameRoundRect”}
- shadow3Doff = 3;
- shadow3Don = 1;
- shadow3Ddiff = shadow3Doff - shadow3Don;
- minBtnHeight = 16;
- minBtnDescent = 4;
- scrWidth = 15;
- scrBarMax =1000;
- noItemHit = -1;
- hiliteMode =$938; {Color highlighting}
- textMarge = 4;
- null = CHR(0);
- vertListDelay = 4;
- threeDDelay = 2;
- feedbackDelay = 10;
- animThreshold = 2; {Ticks between frames}
- listKeyLeng = 15;
- doubleClick = 1;
- endOfStyle = 9;
- origV = 40;
- origH = 2;
- toggleOff = 0;
- toggleOn = 1;
- scrBarShow = 0;
- scrBarHide = 255;
- {------------- RESOURCE ID’S --------------}
- alert1ID = 129;
- blApplID = 1000;
- exclamationBaseID = 1000;
- exclamationNumber = 7; {Number of frames}
- {------------- Menu resources -------------}
- applMID = 1001;
- fileMID = applMID + 1;
- editMID = fileMID + 1;
- fontMID = editMID + 1;
- stylMID = fontMID + 1;
-
- TYPE
- Str1 = String[1];
- StrListKey = String[listKeyLeng];
- CharacterSet= SET OF CHAR;
- FontIdent = PACKED RECORD
- n : INTEGER; {Font number}
- s : Byte; {Font size}
- y : Style; {Font style}
- END;
- MouseIndex = (before, now);
- MouseFlags =
- PACKED ARRAY[MouseIndex] OF BOOLEAN;
- ActivationType = (active, enable, animate);
- PDItemFlagType =
- PACKED ARRAY[ActivationType] OF BOOLEAN;
-
- {------------------ Objects ------------------}
- TPseudoDialog = OBJECT (TObject)
- fWindow : WindowPtr;
- fItems : TPDialogItem;
- fActive : BOOLEAN;
- PROCEDURE Free; OverRide;
- PROCEDURE IPseudoDialog
- (iBounds : Rect;
- iTitle : Str255;
- iWithGA : BOOLEAN;
- iFont : FontIdent);
- PROCEDURE InstallItem(chose : TPDialogItem);
- PROCEDURE ItemInformation;
- PROCEDURE EnableDisableItem
- (index : INTEGER);
- PROCEDURE AnimateStuff;
- PROCEDURE DrawBorder;
- PROCEDURE ActivateWindow;
- PROCEDURE DeactivateWindow;
- PROCEDURE UpdateWindKernel;
- PROCEDURE UpdateWindow;
- PROCEDURE Idling;
- PROCEDURE SetFont;
- FUNCTION Keying(c : CHAR;
- modif : INTEGER) : LongInt;
- FUNCTION MouseInContent(p : Point;
- modif : INTEGER) : LongInt;
- PROCEDURE MouseInDrag(p : Point);
- FUNCTION HandleMouseEvents
- (p : Point;
- modif : INTEGER;
- thePart : INTEGER) : LongInt;
- PROCEDURE RequestResponse
- (theItem, theKind : INTEGER);
- END;
-
- TPDialogItem = OBJECT (TObject)
- fNexThing : TPDialogItem;
- fItsValue : INTEGER;
- fFlag : PDItemFlagType;
- fBorder : Rect;
- PROCEDURE Free; OverRide;
- PROCEDURE IPDialogItem(iBorder : Rect);
- FUNCTION Information : Str255;
- PROCEDURE EnableDisable(index : INTEGER);
- PROCEDURE AnimateIt;
- PROCEDURE GetRectangle(VAR r : Rect);
- PROCEDURE Draw;
- PROCEDURE UpdateIt;
- PROCEDURE ActivateIt;
- PROCEDURE DeactivateIt;
- PROCEDURE Idle;
- PROCEDURE SetItemFont;
- FUNCTION Click(p : Point;
- modif : INTEGER) : LongInt;
- FUNCTION KeyIt(c : CHAR;
- modif : INTEGER) : LongInt;
- PROCEDURE Response(theItem,
- theKind : INTEGER);
- END;
-
- TVerticalList = OBJECT (TPDialogItem)
- fLength, {Entries in list}
- fSelect, {Nº of selected entry}
- fOffLin : LongInt; {Scrolled off top}
- fOffByt : LongInt; {Before first visible}
- fData : Handle; {The entries}
- fFont : FontIdent;
- fHeight, {Cell height, pixels}
- fDescent: INTEGER; {Font descent, pixels}
- fPort : WindowPtr;
- fScroll : ControlHandle;
-
- fUserHitKeys : StrListKey;
- fLastKeyTime : LongInt;
-
- PROCEDURE Free; OverRide;
- PROCEDURE IVerticalList
- (iBorder : Rect;
- iPort : WindowPtr);
- FUNCTION Information : Str255; OverRide;
- PROCEDURE SetMeasures;
- PROCEDURE GetRectangle(VAR r : Rect);
- OverRide;
- FUNCTION VisibleLines : INTEGER;
- PROCEDURE InstallData(theText : Handle);
- PROCEDURE DrawOneEntry(x,y : LongInt);
- PROCEDURE DrawEntries;
- FUNCTION GetSelection : Str63;
- PROCEDURE SelectionRectangle(VAR r : Rect);
- PROCEDURE HiliteSelection;
- PROCEDURE ActivationSel(activate : BOOLEAN);
- PROCEDURE DrawEntsAndSel;
- PROCEDURE DrawBorder;
- PROCEDURE Draw; OverRide;
- PROCEDURE ActivateIt; OverRide;
- PROCEDURE DeactivateIt; OverRide;
- PROCEDURE SetItemFont; OverRide;
- PROCEDURE CheckScrollability;
- PROCEDURE SetScrollValue;
- PROCEDURE OneLineLess;
- PROCEDURE OneLineMore;
- PROCEDURE RecalOffByte;
- PROCEDURE OnePageLess;
- PROCEDURE OnePageMore;
- PROCEDURE Thumbing(p : Point);
- PROCEDURE Scrolling(part : INTEGER);
- PROCEDURE DragSelecting;
- FUNCTION Click(p : Point;
- modif : INTEGER) : LongInt;
- OverRide;
- PROCEDURE CancelSelection;
- PROCEDURE SetSelection(newSel : LongInt);
- PROCEDURE ShowSelection;
- PROCEDURE InitKeyStuff;
- PROCEDURE SelectCellStart(c : CHAR);
- FUNCTION KeyIt(c : CHAR;
- modif : INTEGER) : LongInt;
- OverRide;
- PROCEDURE Response(theItem,
- theKind : INTEGER); OverRide;
- PROCEDURE Resize(hauteur : INTEGER);
- END;
-
- TPlainButton = OBJECT (TPDialogItem)
- fTitle : Str15;
- fEquiv : PACKED ARRAY[1..2] OF CHAR;
- fFont : FontIdent;
- PROCEDURE IPlainButton(iBorder : Rect;
- iTitle : Str15;
- iEquiv : CHAR;
- iFont : FontIdent);
- FUNCTION KeyInfo : Str15;
- FUNCTION ButtonInfo : Str255;
- FUNCTION Information : Str255; OverRide;
- FUNCTION ExtraHeight : INTEGER;
- PROCEDURE DrawTitle(r : Rect);
- PROCEDURE Draw; OverRide;
- PROCEDURE ActivateIt; OverRide;
- PROCEDURE DeactivateIt; OverRide;
- FUNCTION Click(p : Point;
- modif : INTEGER) : LongInt;
- OverRide;
- PROCEDURE Invert(r : Rect);
- FUNCTION MouseReleasedHere : BOOLEAN;
- PROCEDURE VisualFeedback;
- FUNCTION KeyIt(c : CHAR;
- modif : INTEGER) : LongInt;
- OverRide;
- END;
-
- TToggleButton = OBJECT (TPlainButton)
- fStatus : INTEGER;
- PROCEDURE IToggleButton(iBorder : Rect;
- iTitle : Str15;
- iEquiv : CHAR;
- iFont : FontIdent;
- iStatus : INTEGER);
- FUNCTION ButtonInfo : Str255; OverRide;
- FUNCTION ExtraHeight : INTEGER; OverRide;
- PROCEDURE Draw; OverRide;
- FUNCTION Click(p : Point;
- modif : INTEGER) : LongInt;
- OverRide;
- PROCEDURE VisualFeedback; OverRide;
- END;
-
- TThreeDButton = OBJECT (TPlainButton)
- PROCEDURE IThreeDButton
- (iBorder : Rect;
- iTitle : Str15;
- iEquiv : CHAR;
- iFont : FontIdent);
- FUNCTION ButtonInfo : Str255; OverRide;
- FUNCTION ExtraHeight : INTEGER; OverRide;
- PROCEDURE FancyBorder(r : Rect;
- hilited : BOOLEAN);
- PROCEDURE DropShadow(r : Rect;
- depth : INTEGER);
- PROCEDURE Draw; OverRide;
- PROCEDURE PushDown(VAR r : Rect;
- depth : INTEGER);
- PROCEDURE PopUp(VAR r : Rect;
- depth : INTEGER);
- FUNCTION MouseReleasedHere : BOOLEAN;
- OverRide;
- PROCEDURE VisualFeedback; OverRide;
- END;
-
- TToggl3DButton = OBJECT (TThreeDButton)
- fStatus : INTEGER;
- PROCEDURE IToggl3DButton
- (iBorder : Rect;
- iTitle : Str15;
- iEquiv : CHAR;
- iFont : FontIdent;
- iStatus : INTEGER);
- FUNCTION ButtonInfo : Str255; OverRide;
- PROCEDURE Draw; OverRide;
- FUNCTION MouseReleasedHere : BOOLEAN;
- OverRide;
- FUNCTION Click(p : Point;
- modif : INTEGER) : LongInt;
- OverRide;
- PROCEDURE VisualFeedback; OverRide;
- END;
-
- TIcon = OBJECT (TPDialogItem)
- fIconID : INTEGER;
- PROCEDURE IIcon(iBorder : Rect;
- iIconID : INTEGER);
- FUNCTION Information : Str255; OverRide;
- PROCEDURE Draw; OverRide;
- END;
-
- TAnimation = OBJECT (TPDialogItem)
- fBaseID : INTEGER;
- fNumber : INTEGER;
- fCurrent : INTEGER;
- fForward : BOOLEAN; {Direction of animation}
- fLastTim : LongInt;
- PROCEDURE IAnimation(iBorder : Rect;
- iBaseID : INTEGER;
- iNumber : INTEGER);
- FUNCTION Information : Str255; OverRide;
- PROCEDURE NextFrame;
- PROCEDURE Idle; OverRide;
- PROCEDURE Draw; OverRide;
- END;
-
- TStaticText = OBJECT (TPDialogItem)
- fContents : Str255;
- fFont : FontIdent;
- PROCEDURE IStaticText(iBorder : Rect;
- iFont : FontIdent;
- iContents : Str255);
- FUNCTION Information : Str255; OverRide;
- PROCEDURE DrawBorder;
- PROCEDURE Draw; OverRide;
- PROCEDURE ActivateIt; OverRide;
- PROCEDURE DeactivateIt; OverRide;
- END;
-
- VAR
- myMenus : ARRAY[1..menuCount] OF MenuHandle;
- theFontMenu,
- theStylMenu: MenuHandle;
- styleVector: PACKED ARRAY[2..8] OF StyleItem;
- fakeDlg : TPseudoDialog;
- theEvent : EventRecord;
- weAreDone,
- inBckGrnd,
- wneExists,
- dublClick : BOOLEAN;
- forNowFI,
- defaultFI : FontIdent;
- entr,
- cRet,
- left,
- right,
- up,
- down,
- blnkChr : CHAR;
- blnkPtr : Ptr;
- zoomArea,
- dragArea : Rect;
- XCursor,
- waitCursor : CursHandle;
- lastClikPoint : Point;
- lastClikTime : LongInt;
-
- PROCEDURE SetFontIdent(font : FontIdent);
- PROCEDURE SetFontSizeFace(fn,fs : INTEGER;
- fy : Style);
- PROCEDURE GetFontIdent(VAR font : FontIdent);
- PROCEDURE SetFontMenu;
- PROCEDURE SetSizeMenu;
- PROCEDURE SetStylMenu;
- PROCEDURE FontMenuEvent(theItem : INTEGER);
- PROCEDURE StyleMenuEvent(theItem : INTEGER);
- FUNCTION MakeStr1(c : CHAR) : Str1;
- FUNCTION IntString(x : LongInt) : Str15;
- FUNCTION StringInt(s : Str15) : LongInt;
- FUNCTION NumericStr(s : Str255) : BOOLEAN;
- PROCEDURE MyInvertRect(r : Rect);
- PROCEDURE RestoreClip;
- PROCEDURE FrameTop(r : Rect);
- PROCEDURE FrameBot(r : Rect);
- PROCEDURE CentreRect(VAR r : Rect);
- FUNCTION ScrollBarShowHide(b : BOOLEAN) : Byte;
- PROCEDURE SimpleAlert(s : Str255);
- FUNCTION GetKind(w : WindowPtr) : INTEGER;
- PROCEDURE CheckMultipleClicks(p : Point);
-
- IMPLEMENTATION
- {$S Main}
- {••••••••••••••••••••••••••••••••••••••••••••••••}
- { Routines for getting and setting the font, }
- { font size, and font style in the current port. }
- {••••••••••••••••••••••••••••••••••••••••••••••••}
- PROCEDURE SetFontIdent(font : FontIdent);
- BEGIN
- WITH font DO BEGIN
- TextFont(n);
- TextSize(s);
- TextFace(y);
- END;
- END;
-
- PROCEDURE SetFontSizeFace(fn,fs : INTEGER;
- fy : Style);
- BEGIN
- TextFont(fn);
- TextSize(fs);
- TextFace(fy);
- END;
-
- PROCEDURE GetFontIdent(VAR font : FontIdent);
- BEGIN
- WITH font,thePort^ DO BEGIN
- n:= txFont;
- s:= txSize;
- y:= txFace;
- END;
- END;
-
- {••••••••••••••••••••••••••••••••••••••••••••••••}
- { Routines which manage the Font and Style menus,}
- { including highlighting of font sizes in second }
- { half of Style menu. The current font, size and }
- { style are stored in global “forNowFI”. }
- {••••••••••••••••••••••••••••••••••••••••••••••••}
- PROCEDURE SetFontMenu;
- VAR fontName,
- itemName : Str255;
- i,size : INTEGER;
- BEGIN
- GetFontName(forNowFI.n,fontName);
- i:= CountMItems(theFontMenu);
- WHILE i > 0 DO BEGIN
- GetItem(theFontMenu,i,itemName);
- CheckItem(theFontMenu,i,itemName=fontName);
- i:= i - 1;
- END;
- i:= CountMItems(theStylMenu);
- WHILE i > endOfStyle DO BEGIN
- GetItem(theStylMenu,i,itemName);
- IF NumericStr(itemName) THEN BEGIN
- size:= StringInt(itemName);
- IF RealFont(forNowFI.n,size) THEN
- SetItemStyle(theStylMenu,
- i,[bold,outline])
- ELSE SetItemStyle(theStylMenu,i,[]);
- END;
- i:= i - 1;
- END;
- END;
-
- PROCEDURE SetSizeMenu;
- VAR i : INTEGER;
- fSize : String[3];
- iSize : Str255;
- BEGIN
- fSize:= IntString(forNowFI.s);
- i:= CountMItems(theStylMenu);
- WHILE i > endOfStyle DO BEGIN
- GetItem(theStylMenu,i,iSize);
- CheckItem(theStylMenu,i,iSize = fSize);
- i:= i - 1;
- END;
- END;
-
- PROCEDURE SetStylMenu;
- VAR i : INTEGER;
- BEGIN
- CheckItem(theStylMenu,1,(forNowFI.y = []));
- FOR i:= 2 TO endOfStyle-1 DO CheckItem
- (theStylMenu,i,
- (styleVector[i] IN forNowFI.y));
- END;
-
- {••••••••••••••••••••••••••••••••••••••••••••••••}
- { Routines which respond to mouse hits in the }
- { Font and Style menus. }
- {••••••••••••••••••••••••••••••••••••••••••••••••}
- PROCEDURE FontMenuEvent(theItem : INTEGER);
- VAR theName : Str255;
- BEGIN
- GetItem(theFontMenu,theItem,theName);
- GetFNum(theName,theItem);
- IF theItem <> forNowFI.n THEN BEGIN
- forNowFI.n:= theItem;
- SetFontMenu;
- END;
- END;
-
- PROCEDURE StyleMenuEvent(theItem : INTEGER);
- VAR theName : Str255;
- theStyle : StyleItem;
- BEGIN
- IF theItem < endOfStyle THEN BEGIN
- IF theItem = 1 THEN forNowFI.y:= []
- ELSE BEGIN
- theStyle:= styleVector[theItem];
- IF theStyle IN forNowFI.y THEN
- forNowFI.y:= forNowFI.y - [theStyle]
- ELSE BEGIN
- forNowFI.y:= forNowFI.y + [theStyle];
- IF theStyle = condense THEN
- forNowFI.y:= forNowFI.y - [extend]
- ELSE IF theStyle = extend THEN
- forNowFI.y:= forNowFI.y-[condense];
- END;
- END;
- SetStylMenu;
- END
- ELSE IF theItem > endOfStyle THEN BEGIN
- GetItem(theStylMenu,theItem,theName);
- IF NumericStr(theName) THEN BEGIN
- theItem:= StringInt(theName);
- IF theItem <> forNowFI.s THEN BEGIN
- forNowFI.s:= theItem;
- SetSizeMenu;
- END;
- END
- ELSE SysBeep(1);
- END;
- END;
-
- {••••••••••••••••••••••••••••••••••••••••••••••••}
- { Various string-conversion routines. }
- {••••••••••••••••••••••••••••••••••••••••••••••••}
- FUNCTION MakeStr1(c : CHAR) : Str1;
- VAR s : Str1;
- BEGIN
- s[0]:= CHR(1);
- s[1]:= c;
- MakeStr1:= s;
- END;
-
- { “IntString” converts "x" to string. }
- FUNCTION IntString(x : LongInt) : Str15;
- VAR s : Str255;
- BEGIN
- NumToString(x,s);
- IF Length(s) > 15 THEN s[0]:= CHR(15);
- IntString:= s;
- END;
-
- { “StringInt” converts numeric “s” to LongInt}
- FUNCTION StringInt(s : Str15) : LongInt;
- VAR x : LongInt;
- BEGIN StringToNum(s,x); StringInt:= x; END;
-
- { “NumericStr” is a Boolean function, TRUE
- if and only if “s” is entirely numeric,
- with no leading sign, & of length at least 1. }
- FUNCTION NumericStr(s : Str255) : BOOLEAN;
- VAR i : INTEGER;
- BEGIN
- NumericStr:= FALSE; {Default}
- i:= Length(s);
- IF i = 0 THEN Exit(NumericStr);
- REPEAT
- IF NOT (s[i] IN ['0'..'9']) THEN
- Exit(NumericStr);
- i:= i - 1;
- UNTIL i = 0;
- NumericStr:= TRUE;
- END;
-
- {••••••••••••••••••••••••••••••••••••••••••••••••}
- { Various graphic routines. }
- {••••••••••••••••••••••••••••••••••••••••••••••••}
- PROCEDURE MyInvertRect(r : Rect);
- BEGIN
- BitClr(Ptr(hiliteMode),pHiliteBit);
- InvertRect(r);
- END;
-
- PROCEDURE RestoreClip;
- VAR i : INTEGER;
- r : Rect;
- BEGIN
- i:= MaxInt DIV 2;
- SetRect(r,-i,-i,i,i);
- ClipRect(r);
- END;
-
- PROCEDURE FrameTop(r : Rect);
- BEGIN
- MoveTo(r.left, r.bottom-1);
- LineTo(r.left, r.top);
- LineTo(r.right-1,r.top);
- END;
-
- PROCEDURE FrameBot(r : Rect);
- BEGIN
- MoveTo(r.left, r.bottom-1);
- LineTo(r.right-1,r.bottom-1);
- LineTo(r.right-1,r.top);
- END;
-
- PROCEDURE CentreRect(VAR r : Rect);
- VAR x,y : INTEGER;
- BEGIN
- WITH zoomArea DO BEGIN
- x:= ((right -left)-(r.right -r.left)) DIV 2;
- y:= ((bottom-top )-(r.bottom-r.top )) DIV 2;
- END;
- OffsetRect(r,x,y+origV);
- END;
-
- FUNCTION ScrollBarShowHide(b : BOOLEAN) : Byte;
- BEGIN
- IF b THEN ScrollBarShowHide:= scrBarShow
- ELSE ScrollBarShowHide:= scrBarHide;
- END;
-
- {••••••••••••••••••••••••••••••••••••••••••••••••}
- { Miscellaneous routines…… }
- {••••••••••••••••••••••••••••••••••••••••••••••••}
- { Alert box with one message & OK button }
- PROCEDURE SimpleAlert(s : Str255);
- VAR g : GrafPtr;
- BEGIN
- GetPort(g);
- SetCursor(arrow);
- ParamText(s,'','','');
- IF NoteAlert(alert1ID,NIL) = ok THEN {Nada};
- SetCursor(waitCursor^^);
- SetPort(g);
- END;
-
- { Returns windowKind of “w”. Zero if “w” is NIL.}
- FUNCTION GetKind(w : WindowPtr) : INTEGER;
- BEGIN
- IF w = NIL THEN GetKind:= 0
- ELSE GetKind:= WindowPeek(w)^.windowKind;
- END;
-
- { Check for double clicks }
- PROCEDURE CheckMultipleClicks(p : Point);
- CONST clickSeuil = 4;
- BEGIN
- dublClick:=
- (theEvent.when-lastClikTime) <= GetDblTime;
- IF dublClick THEN BEGIN
- SubPt(lastClikPoint,p);
- dublClick:= (ABS(p.h) < clickSeuil) AND
- (ABS(p.v) < clickSeuil);
- { Don’t report a double-click until
- the mouse button is released. }
- IF dublClick THEN
- REPEAT UNTIL NOT WaitMouseUp;
- END;
- lastClikPoint:= theEvent.where;
- lastClikTime := theEvent.when;
- END;
-
- { Encode low-word & high-word into a LongInt }
- FUNCTION MakeLongInt(lo,hi : INTEGER) : LongInt;
- BEGIN MakeLongInt:= lo + hi*$00010000; END;
-
- {••••••••••••••••••••••••••••••••••••••••••••••••}
- { METHODS OF OBJECT TYPE “TPseudoDialog”. }
- {••••••••••••••••••••••••••••••••••••••••••••••••}
- PROCEDURE TPseudoDialog.Free;
- VAR p : Ptr;
- BEGIN
- IF fItems <> NIL THEN fItems.Free;
- p:= Ptr(fWindow);
- CloseWindow(fWindow);
- DisposPtr(p);
- INHERITED Free;
- END;
-
- PROCEDURE TPseudoDialog.IPseudoDialog
- (iBounds : Rect;
- iTitle : Str255;
- iWithGA : BOOLEAN;
- iFont : FontIdent);
- VAR wStorage : Ptr;
- BEGIN
- wStorage:= NewPtr(SizeOf(WindowRecord));
- IF wStorage = NIL THEN ExitToShell;
- fWindow:= NewWindow(wStorage,iBounds,
- iTitle,FALSE,noGrowDocProc,
- WindowPtr(-1),iWithGA,ORD(SELF));
- SetPort(fWindow);
- SetFontIdent(iFont);
- fItems:= NIL;
- fActive:= FALSE;
- END;
-
- { Install “chose” at end of linked list
- headed by “fItems”;
- also initialize “chose.fItsValue”.}
- PROCEDURE TPseudoDialog.InstallItem
- (chose : TPDialogItem);
- VAR scan : TPDialogItem;
- BEGIN
- IF fItems = NIL THEN BEGIN
- chose.fItsValue:= 1;
- fItems:= chose;
- END
- ELSE BEGIN
- chose.fItsValue:= 2;
- scan:= fItems;
- WHILE scan.fNexThing <> NIL DO BEGIN
- chose.fItsValue:= chose.fItsValue + 1;
- scan:= scan.fNexThing;
- END;
- scan.fNexThing:= chose;
- END;
- END;
-
- PROCEDURE TPseudoDialog.ItemInformation;
- CONST lineHeight = 15;
- VAR w : WindowPtr;
- r : Rect;
- s : Str255;
- p : TPDialogItem;
- i : INTEGER;
- BEGIN
- DeactivateWindow;
- SetRect(r,0,0,420,250); CentreRect(r);
- GetWTitle(fWindow,s);
- s:= Concat('Items in “',s,'”');
- w:= NewWindow(NIL,r,s,TRUE,noGrowDocProc,
- WindowPtr(-1),FALSE,0);
- SetPort(w);
- SetFontSizeFace(geneva,9,[bold]);
- i:= 0;
- r:= w^.portRect; r.left:= r.left + 5;
- p:= fItems;
- WHILE p <> NIL DO BEGIN
- i:= i + 1;
- r.top:= r.top + lineHeight;
- MoveTo(r.left,r.top);
- s:= p.Information;
- s:= Concat(IntString(i),'. ',s);
- IF i < 10 THEN s:= Concat(blnkChr,s);
- DrawString(s);
- p:= p.fNexThing;
- END;
- REPEAT SystemTask UNTIL Button;
- FlushEvents(everyEvent,0);
- DisposeWindow(w);
- END;
-
- PROCEDURE TPseudoDialog.EnableDisableItem
- (index : INTEGER);
- BEGIN
- IF fItems <> NIL THEN BEGIN
- SetPort(fWindow);
- fItems.EnableDisable(index);
- END;
- END;
-
- PROCEDURE TPseudoDialog.AnimateStuff;
- BEGIN
- IF fItems <> NIL THEN BEGIN
- SetPort(fWindow);
- fItems.AnimateIt;
- END;
- END;
-
- PROCEDURE TPseudoDialog.DrawBorder;
- VAR r : Rect;
- BEGIN
- r:= fWindow^.portRect;
- InsetRect(r,2,2);
- PenSize(2,2);
- IF fActive THEN PenPat(black)
- ELSE PenPat(gray);
- FrameRect(r);
- PenNormal;
- END;
-
- PROCEDURE TPseudoDialog.ActivateWindow;
- BEGIN
- {Following line prevents multiple activation}
- IF fActive THEN Exit(ActivateWindow);
- fActive:= TRUE;
- SetPort(fWindow);
- DrawBorder;
- IF fItems <> NIL THEN fItems.ActivateIt;
- END;
-
- PROCEDURE TPseudoDialog.DeactivateWindow;
- BEGIN
- {Following line prevents multiple deactivation}
- IF NOT fActive THEN Exit(DeactivateWindow);
- fActive:= FALSE;
- SetPort(fWindow);
- DrawBorder;
- IF fItems <> NIL THEN fItems.DeactivateIt;
- END;
-
- PROCEDURE TPseudoDialog.UpdateWindKernel;
- BEGIN
- DrawBorder;
- IF fItems <> NIL THEN fItems.UpdateIt;
- END;
-
- PROCEDURE TPseudoDialog.UpdateWindow;
- VAR g : GrafPtr;
- BEGIN
- GetPort(g);
- SetPort(fWindow);
- BeginUpdate(fWindow);
- UpdateWindKernel;
- EndUpdate(fWindow);
- SetPort(g);
- END;
-
- PROCEDURE TPseudoDialog.Idling;
- BEGIN
- IF fItems <> NIL THEN fItems.Idle;
- END;
-
- PROCEDURE TPseudoDialog.SetFont;
- VAR g : GrafPtr;
- BEGIN
- GetPort(g);
- SetPort(fWindow);
- fItems.SetItemFont;
- SetPort(g);
- END;
-
- FUNCTION TPseudoDialog.Keying
- (c : CHAR; modif : INTEGER) : LongInt;
- VAR result : INTEGER;
- BEGIN
- IF fItems = NIL
- THEN Keying:= noItemHit
- ELSE Keying:= fItems.KeyIt(c,modif);
- END;
-
- FUNCTION TPseudoDialog.MouseInContent(p : Point;
- modif : INTEGER) : LongInt;
- BEGIN
- MouseInContent:= noItemHit; {Default}
- IF fItems = NIL THEN Exit(MouseInContent);
- CheckMultipleClicks(p);
- GlobalToLocal(p);
- MouseInContent:= fItems.Click(p,modif);
- END;
-
- PROCEDURE TPseudoDialog.MouseInDrag(p : Point);
- BEGIN DragWindow(fWindow,p,dragArea); END;
- FUNCTION TPseudoDialog.HandleMouseEvents
- (p : Point;
- modif : INTEGER;
- thePart : INTEGER) : LongInt;
- BEGIN
- HandleMouseEvents:= noItemHit; {Default}
- CASE thePart OF
- inContent:IF fWindow <> FrontWindow
- THEN SelectWindow(fWindow)
- ELSE HandleMouseEvents:=
- MouseInContent(p,modif);
- inDrag:MouseInDrag(p);
- END;
- END;
-
- PROCEDURE TPseudoDialog.RequestResponse
- (theItem, theKind : INTEGER);
- BEGIN
- IF fItems <> NIL THEN
- fItems.Response(theItem,theKind);
- END;
-
- {••••••••••••••••••••••••••••••••••••••••••••••••}
- { METHODS OF OBJECT TYPE “TPDialogItem”. }
- {••••••••••••••••••••••••••••••••••••••••••••••••}
- PROCEDURE TPDialogItem.Free;
- BEGIN
- IF fNexThing <> NIL THEN fNexThing.Free;
- INHERITED Free;
- END;
-
- PROCEDURE TPDialogItem.IPDialogItem(iBorder:Rect);
- BEGIN
- fNexThing:= NIL; fItsValue:= noItemHit;
- { The above will be re-initialized
- by “TPseudoDialog.InstallItem” }
- fFlag[active] := FALSE;
- fFlag[enable] := FALSE;
- fFlag[animate]:= FALSE;
- fBorder:= iBorder;
- END;
-
- FUNCTION TPDialogItem.Information : Str255;
- BEGIN
- Information:= '[Generic item]';
- END;
-
- PROCEDURE TPDialogItem.EnableDisable
- (index : INTEGER);
- BEGIN
- IF index = fItsValue THEN BEGIN
- fFlag[enable]:= NOT fFlag[enable];
- Draw;
- END
- ELSE IF fNexThing <> NIL THEN
- fNexThing.EnableDisable(index);
- END;
-
- PROCEDURE TPDialogItem.AnimateIt;
- BEGIN
- fFlag[animate]:= NOT fFlag[animate];
- IF fNexThing <> NIL THEN fNexThing.AnimateIt;
- END;
-
- PROCEDURE TPDialogItem.GetRectangle(VAR r : Rect);
- BEGIN r:= fBorder; END;
-
- PROCEDURE TPDialogItem.Draw; {Dummy ancestor}
- BEGIN SysBeep(1); END;
-
- { Method “UpdateIt” must be sandwiched
- between “BeginUpdate” & “EndUpdate”.}
- PROCEDURE TPDialogItem.UpdateIt;
- BEGIN
- Draw;
- IF fNexThing <> NIL THEN fNexThing.UpdateIt;
- END;
-
- PROCEDURE TPDialogItem.ActivateIt;
- BEGIN
- IF fNexThing <> NIL THEN fNexThing.ActivateIt;
- END;
-
- PROCEDURE TPDialogItem.DeactivateIt;
- BEGIN
- IF fNexThing<>NIL THEN fNexThing.DeactivateIt;
- END;
-
- PROCEDURE TPDialogItem.Idle;
- BEGIN
- IF fNexThing <> NIL THEN fNexThing.Idle;
- END;
-
- PROCEDURE TPDialogItem.SetItemFont;
- BEGIN
- IF fNexThing <> NIL THEN fNexThing.SetItemFont;
- END;
-
- FUNCTION TPDialogItem.Click
- (p : Point; modif : INTEGER) : LongInt;
- VAR r : Rect;
- BEGIN
- GetRectangle(r);
- IF PtInRect(p,r) THEN BEGIN
- IF fFlag[enable] THEN Click:= fItsValue
- ELSE Click:= noItemHit;
- END
- ELSE IF fNexThing = NIL THEN Click:= noItemHit
- ELSE Click:= fNexThing.Click(p,modif);
- END;
-
- { Method “KeyIt” is a function so we can return an
- item number if appropriate for a particular key}
- FUNCTION TPDialogItem.KeyIt
- (c : CHAR; modif : INTEGER) : LongInt;
- BEGIN
- IF fNexThing = NIL THEN KeyIt:= noItemHit
- ELSE KeyIt:= fNexThing.KeyIt(c,modif);
- END;
-
- PROCEDURE TPDialogItem.Response
- (theItem,theKind : INTEGER);
- BEGIN
- IF fNexThing <> NIL THEN
- fNexThing.Response(theItem,theKind);
- END;
-
- {••••••••••••••••••••••••••••••••••••••••••••••••}
- { METHODS OF OBJECT TYPE “TVerticalList”. }
- {••••••••••••••••••••••••••••••••••••••••••••••••}
- PROCEDURE TVerticalList.Free;
- BEGIN
- IF fData <> NIL THEN DisposHandle(fData);
- INHERITED Free;
- END;
-
- PROCEDURE TVerticalList.IVerticalList
- (iBorder : Rect; iPort : WindowPtr);
- BEGIN
- IPDialogItem(iBorder);
- fFlag[enable]:= TRUE; {Override the default}
- fLength:= 0;
- fSelect:= 0;
- fOffLin:= 0;
- fOffByt:= 0;
- fData := NIL;
- fFont := forNowFI;
- SetMeasures;
- iBorder.left:= iBorder.right - scrWidth + 1;
- InsetRect(iBorder,-1,-1);
- fPort := iPort;
- fScroll:= NewControl(iPort,iBorder,'',FALSE,
- 0,0,scrBarMax,scrollBarProc,0);
- InitKeyStuff;
- END;
-
- FUNCTION TVerticalList.Information : Str255;
- VAR s : Str255;
- BEGIN
- s:= Concat('List, ',
- IntString(fLength),' entries, ');
- IF fSelect = 0 THEN
- s:= Concat(s,'nothing selected, ')
- ELSE s:= Concat(s,'#',
- IntString(fSelect),' selected, ');
- s:= Concat(s,IntString(fOffLin),
- ' entries scrolled off top.');
- Information:= s;
- END;
-
- PROCEDURE TVerticalList.SetMeasures;
- VAR f : FontIdent;
- fm : FMetricRec;
- BEGIN
- f:= fFont;
- SetFontIdent(f);
- FontMetrics(fm);
- WITH fm DO BEGIN
- fHeight := FixRound(ascent+descent+leading);
- fDescent:= FixRound(descent);
- END;
- END;
-
- PROCEDURE TVerticalList.GetRectangle(VAR r:Rect);
- BEGIN
- r:= fBorder;
- r.right:= r.right - scrWidth;
- END;
-
- FUNCTION TVerticalList.VisibleLines : INTEGER;
- BEGIN
- VisibleLines:=
- (fBorder.bottom - fBorder.top) DIV fHeight;
- END;
-
- PROCEDURE TVerticalList.InstallData
- (theText : Handle);
- VAR x,lastOne,nextOne : LongInt;
- BEGIN
- fLength:= 0;
- fSelect:= 0;
- fOffLin:= 0;
- fOffByt:= 0;
- IF fData <> NIL THEN DisposHandle(fData);
- fData:= theText;
- IF fData = NIL THEN Exit(InstallData);
- HLock(fData);
- x:= GetHandleSize(fData)-1; {Blank at end}
- nextOne:= 0;
- WHILE nextOne < x DO BEGIN
- lastOne:= nextOne + 1;
- nextOne:=
- Munger(fData,lastOne,blnkPtr,1,NIL,0);
- fLength:= fLength + 1;
- IF nextOne < 0 THEN nextOne:= x; {Error!}
- END;
- HUnLock(fData);
- Draw;
- END;
-
- PROCEDURE TVerticalList.DrawOneEntry(x,y:LongInt);
- BEGIN
- y:= y - x;
- IF y > MaxInt THEN y:= MaxInt;
- DrawText(Ptr(ORD(fData^)+x),0,y);
- END;
-
- { “DrawEntries” just draws the entries, with
- port, clip & font maintenance done elsewhere. }
- PROCEDURE TVerticalList.DrawEntries;
- VAR i,lastOne,nextOne,y : LongInt;
- x : INTEGER;
- PROCEDURE ExitDE;
- BEGIN HUnLock(fData); Exit(DrawEntries); END;
- BEGIN
- i:= fOffLin;
- x:= fBorder.left + textMarge;
- nextOne:= fOffByt;
- HLock(fData);
- WHILE i < fLength DO BEGIN
- i:= i + 1;
- lastOne:= nextOne + 1;
- nextOne:=
- Munger(fData,lastOne,blnkPtr,1,NIL,0);
- IF nextOne < 0 THEN ExitDE; {Error!}
- IF i > fOffLin THEN BEGIN
- y:= fBorder.top + (i-fOffLin)*fHeight;
- IF y > fBorder.bottom THEN ExitDE;
- MoveTo(x,y-fDescent);
- DrawOneEntry(lastOne,nextOne);
- END;
- END;
- ExitDE;
- END;
-
- FUNCTION TVerticalList.GetSelection : Str63;
- VAR s : Str63;
- i : INTEGER;
- x,lastOne,nextOne : LongInt;
- PROCEDURE ExitGS;
- BEGIN
- HUnLock(fData);
- GetSelection:= s;
- Exit(GetSelection);
- END;
- BEGIN
- s:= '';
- x:= fOffLin;
- nextOne:= fOffByt;
- HLock(fData);
- WHILE x < fSelect DO BEGIN
- x:= x + 1;
- lastOne:= nextOne + 1;
- nextOne:=
- Munger(fData,lastOne,blnkPtr,1,NIL,0);
- IF nextOne < 0 THEN ExitGS; {Error!}
- END;
- i:= nextOne - lastOne;
- IF i > 63 THEN i:= 63;
- BlockMove(Ptr(ORD(fData^)+lastOne),
- Ptr(ORD(@s)+1),i);
- s[0]:= CHR(i);
- ExitGS;
- END;
-
- PROCEDURE TVerticalList.SelectionRectangle
- (VAR r : Rect);
- VAR i : LongInt;
- PROCEDURE SelectionNotVisible;
- BEGIN
- SetRect(r,0,0,0,0);
- Exit(SelectionRectangle);
- END;
- BEGIN
- i:= fSelect - fOffLin;
- IF i <= 0 THEN SelectionNotVisible;
- GetRectangle(r);
- i:= r.top + i*fHeight;
- IF i > r.bottom THEN SelectionNotVisible;
- r.bottom:= i;
- r.top:= i - fHeight;
- END;
-
- PROCEDURE TVerticalList.HiliteSelection;
- VAR r : Rect;
- BEGIN
- SelectionRectangle(r);
- IF EqualPt(r.topLeft,r.botRight) THEN
- Exit(HiliteSelection);
- BitClr(Ptr(hiliteMode),pHiliteBit);
- IF fFlag[active] THEN InvertRect(r)
- ELSE BEGIN
- PenSize(2,2);
- FrameRect(r);
- PenNormal;
- END;
- END;
-
- PROCEDURE TVerticalList.ActivationSel
- (activate : BOOLEAN);
- VAR r : Rect;
- BEGIN
- IF fFlag[active] = activate THEN
- Exit(ActivationSel);
- fFlag[active]:= activate;
- SelectionRectangle(r);
- IF EqualPt(r.topLeft,r.botRight) THEN
- Exit(ActivationSel);
- InsetRect(r,2,2);
- MyInvertRect(r);
- END;
-
- PROCEDURE TVerticalList.DrawEntsAndSel;
- VAR r : Rect;
- BEGIN
- GetRectangle(r);
- ClipRect(r);
- EraseRect(r);
- IF fData <> NIL THEN BEGIN
- DrawEntries;
- HiliteSelection;
- END;
- RestoreClip;
- END;
-
- PROCEDURE TVerticalList.DrawBorder;
- VAR r : Rect;
- BEGIN
- GetRectangle(r);
- InsetRect(r,-1,-1);
- FrameRect(r);
- END;
-
- PROCEDURE TVerticalList.Draw;
- VAR r : Rect;
- f : FontIdent;
- BEGIN
- f:= fFont;
- SetFontIdent(f);
- DrawBorder;
- DrawEntsAndSel;
- Draw1Control(fScroll);
- END;
-
- PROCEDURE TVerticalList.ActivateIt;
- BEGIN
- ActivationSel(TRUE);
- ShowControl(fScroll);
- INHERITED ActivateIt;
- END;
-
- PROCEDURE TVerticalList.DeactivateIt;
- VAR r : Rect;
- BEGIN
- ActivationSel(FALSE);
- HideControl(fScroll);
- DrawBorder;
- INHERITED DeactivateIt;
- END;
-
- PROCEDURE TVerticalList.SetItemFont;
- BEGIN
- fFont:= forNowFI;
- SetMeasures;
- Draw;
- INHERITED SetItemFont;
- END;
-
- PROCEDURE TVerticalList.CheckScrollability;
- VAR vis : INTEGER;
- BEGIN
- IF fData = NIL THEN
- HiliteControl(fScroll,scrBarHide)
- ELSE IF fOffLin > 0 THEN
- HiliteControl(fScroll,scrBarShow)
- ELSE BEGIN
- vis:= VisibleLines;
- HiliteControl(fScroll,
- ScrollBarShowHide(fLength > vis));
- END;
- END;
-
- PROCEDURE TVerticalList.SetScrollValue;
- VAR max,
- min,
- vis : INTEGER;
- ratio : Fract;
- BEGIN
- min:= GetCtlMin(fScroll);
- max:= GetCtlMax(fScroll);
- vis:= VisibleLines;
- IF fLength <= vis THEN SetCtlValue(fScroll,min)
- ELSE BEGIN
- ratio:= FracDiv(fOffLin, fLength-vis);
- SetCtlValue(fScroll,FracMul(ratio,max-min));
- END;
- END;
-
- PROCEDURE TVerticalList.OneLineLess;
- VAR r : Rect;
- rgn : RgnHandle;
- PROCEDURE DrawFirstLine;
- VAR i : LongInt;
- c : Str1;
- BEGIN
- i:= fOffByt;
- REPEAT
- i:= i - 1;
- IF i < 0 THEN Exit(DrawFirstLine);
- BlockMove(Ptr(ORD(fData^)+i),@c,1);
- UNTIL c[0] = blnkChr;
- MoveTo(r.left+textMarge,
- r.top+fHeight-fDescent);
- DrawOneEntry(i+1,fOffByt);
- IF fSelect = fOffLin THEN BEGIN
- r.bottom:= r.top + fHeight;
- MyInvertRect(r);
- END;
- fOffLin:= fOffLin - 1;
- fOffByt:= i;
- END;
- PROCEDURE EraseLastLine;
- VAR saveTop : INTEGER;
- BEGIN
- saveTop:= r.top;
- r.top:= r.top + VisibleLines*fHeight;
- EraseRect(r);
- r.top:= saveTop;
- END;
- BEGIN
- IF fOffLin <= 0 THEN Exit(OneLineLess);
- GetRectangle(r);
- ClipRect(r);
- rgn:= NewRgn;
- ScrollRect(r,0,fHeight,rgn);
- EraseLastLine;
- DisposeRgn(rgn);
- HLock(fData);
- DrawFirstLine;
- HUnLock(fData);
- RestoreClip;
- END;
-
- PROCEDURE TVerticalList.OneLineMore;
- VAR r : Rect;
- rgn : RgnHandle;
- vis : INTEGER;
- PROCEDURE DrawLastLine;
- VAR thisLine,
- lastLine,
- lastOne,
- nextOne : LongInt;
- BEGIN
- fOffLin:= fOffLin + 1;
- fOffByt:=
- Munger(fData,fOffByt+1,blnkPtr,1,NIL,0);
- IF nextOne < 0 THEN Exit(DrawLastLine);
-
- thisLine:= fOffLin;
- lastLine:= fOffLin + vis;
- nextOne:= fOffByt;
- WHILE thisLine < lastLine DO BEGIN
- thisLine:= thisLine + 1;
- lastOne:= nextOne + 1;
- nextOne:=
- Munger(fData,lastOne,blnkPtr,1,NIL,0);
- IF nextOne < 0 THEN Exit(DrawLastLine);
- END;
- r.bottom:= r.top + vis*fHeight;
- MoveTo(r.left+textMarge, r.bottom-fDescent);
- DrawOneEntry(lastOne,nextOne);
- IF fSelect = lastLine THEN BEGIN
- r.top:= r.bottom - fHeight;
- MyInvertRect(r);
- END;
- END;
- BEGIN
- vis:= VisibleLines;
- IF fOffLin>=fLength-vis THEN Exit(OneLineMore);
- GetRectangle(r);
- ClipRect(r);
- rgn:= NewRgn;
- ScrollRect(r,0,-fHeight,rgn);
- DisposeRgn(rgn);
- HLock(fData);
- DrawLastLine;
- HUnLock(fData);
- RestoreClip;
- END;
-
- { “RecalOffByte” recalculates "fOffByt". }
- PROCEDURE TVerticalList.RecalOffByte;
- VAR i,lastOne : LongInt;
-
- PROCEDURE ExitROB;
- BEGIN HUnLock(fData); Exit(RecalOffByte); END;
- BEGIN
- SetCursor(waitCursor^^);
- i:= 0;
- fOffByt:= 0;
- HLock(fData);
- WHILE i < fOffLin DO BEGIN
- i:= i + 1;
- lastOne:= fOffByt + 1;
- fOffByt:=
- Munger(fData,lastOne,blnkPtr,1,NIL,0);
- IF fOffByt < 0 THEN BEGIN
- fOffLin:= 0;
- fOffByt:= 0;
- ExitROB;
- END;
- END;
- ExitROB;
- END;
-
- PROCEDURE TVerticalList.OnePageLess;
- VAR newOffLine : LongInt;
- c : Str1;
- BEGIN
- IF fOffLin <= 0 THEN Exit(OnePageLess);
- newOffLine:= fOffLin - (VisibleLines-1);
- IF newOffLine <= 0 THEN BEGIN
- fOffLin:= 0;
- fOffByt:= 0;
- END
- ELSE WHILE fOffLin > newOffLine DO BEGIN
- fOffLin:= fOffLin - 1;
- REPEAT
- fOffByt:= fOffByt - 1;
- BlockMove(Ptr(ORD(fData^)+fOffByt),@c,1);
- UNTIL c[0] = blnkChr;
- END;
- DrawEntsAndSel;
- END;
-
- PROCEDURE TVerticalList.OnePageMore;
- VAR vis : INTEGER;
- max,
- newOffLine : LongInt;
- BEGIN
- vis:= VisibleLines;
- max:= fLength - vis;
- IF fOffLin >= max THEN Exit(OnePageMore);
- newOffLine:= fOffLin + (vis-1);
- IF newOffLine > max THEN newOffLine:= max;
- WHILE fOffLin < newOffLine DO BEGIN
- fOffLin:= fOffLin + 1;
- fOffByt:=
- Munger(fData,fOffByt+1,blnkPtr,1,NIL,0);
- END;
- DrawEntsAndSel;
- END;
-
- PROCEDURE TVerticalList.Thumbing(p : Point);
- VAR min,
- apres : INTEGER;
- vis,
- avant : LongInt;
- ratio : Fract;
- BEGIN
- min:= GetCtlMin(fScroll);
- avant:= GetCtlValue(fScroll);
- apres:= TrackControl(fScroll,p,NIL);
- apres:= GetCtlValue(fScroll);
- IF apres <> avant THEN BEGIN
- vis:= VisibleLines;
- IF fLength <= vis THEN
- SetCtlValue(fScroll,min)
- ELSE BEGIN
- avant:= fOffLin;
- ratio:= FracDiv(apres-min,
- GetCtlMax(fScroll)-min);
- vis:= fLength - vis;
- fOffLin:= FracMul(ratio,vis);
- IF fOffLin < 0 THEN fOffLin:= 0
- ELSE IF fOffLin > vis THEN fOffLin:= vis;
- IF fOffLin <> avant THEN BEGIN
- RecalOffByte;
- CheckScrollability;
- DrawEntsAndSel;
- END;
- END;
- END;
- END;
-
- PROCEDURE TVerticalList.Scrolling(part : INTEGER);
- VAR x : LongInt;
- r : Rect;
- BEGIN
- CASE part OF
- inUpButton:
- BEGIN
- HiliteControl(fScroll,part);
- WHILE StillDown DO BEGIN
- Delay(vertListDelay,x);
- OneLineLess;
- SetScrollValue;
- END;
- HiliteControl(fScroll,toggleOff);
- END;
- inDownButton:
- BEGIN
- HiliteControl(fScroll,part);
- WHILE StillDown DO BEGIN
- Delay(vertListDelay,x);
- OneLineMore;
- SetScrollValue;
- END;
- HiliteControl(fScroll,toggleOff);
- GetRectangle(r);
- r.top:= r.top + VisibleLines*fHeight;
- InvalRect(r);
- END;
- inPageUp:
- WHILE StillDown DO BEGIN
- Delay(vertListDelay,x);
- OnePageLess;
- SetScrollValue;
- END;
- inPageDown:
- WHILE StillDown DO BEGIN
- Delay(vertListDelay,x);
- OnePageMore;
- SetScrollValue;
- END;
- END;
- CheckScrollability;
- END;
-
- PROCEDURE TVerticalList.DragSelecting;
- VAR r : Rect;
- p : Point;
- vis : INTEGER;
- lineHit : LongInt;
- BEGIN
- GetRectangle(r);
- vis:= (r.bottom - r.top) DIV fHeight;
- REPEAT
- GetMouse(p);
- IF PtInRect(p,r) THEN BEGIN
- lineHit:=
- fOffLin + (p.v-r.top) DIV fHeight + 1;
- SetSelection(lineHit);
- END
- ELSE IF p.v < r.top THEN BEGIN
- OneLineLess;
- SetScrollValue;
- SetSelection(fOffLin+1);
- END
- ELSE IF p.v > r.bottom THEN BEGIN
- OneLineMore;
- SetScrollValue;
- SetSelection(fOffLin+vis);
- END;
- UNTIL NOT StillDown;
- END;
-
- FUNCTION TVerticalList.Click
- (p : Point; modif : INTEGER) : LongInt;
- VAR r : Rect;
- f : FontIdent;
- c : ControlHandle;
- part : INTEGER;
- PROCEDURE ClickInEntries;
- VAR i : INTEGER;
- lineHit : LongInt;
- BEGIN
- SetFontIdent(f);
- Click:= fItsValue;
- i:= (p.v - r.top) DIV fHeight + 1;
- lineHit:= fOffLin + i;
- IF BAnd(modif,shiftKey) = 0 THEN BEGIN
- SetSelection(lineHit);
- IF dublClick THEN BEGIN
- GetMouse(p);
- r.bottom:= r.top + i*fHeight;
- r.top := r.bottom - fHeight;
- IF PtInRect(p,r) THEN Click:=
- MakeLongInt(fItsValue,doubleClick);
- END
- ELSE IF StillDown THEN DragSelecting;
- END
- { Below, shift-clicking }
- ELSE IF fSelect=lineHit THEN CancelSelection
- ELSE SetSelection(lineHit);
- END;
- BEGIN
- GetRectangle(r);
- part:= FindControl(p,fPort,c);
- f:= fFont;
- IF c = fScroll THEN BEGIN
- SetFontIdent(f);
- Click:= fItsValue;
- IF part = inThumb THEN Thumbing(p)
- ELSE Scrolling(part);
- END
- ELSE IF PtInRect(p,r) THEN ClickInEntries
- ELSE IF fNexThing = NIL THEN Click:= noItemHit
- ELSE Click:= fNexThing.Click(p,modif);
- END;
-
- PROCEDURE TVerticalList.CancelSelection;
- BEGIN
- IF fSelect = 0 THEN Exit(CancelSelection);
- HiliteSelection;
- fSelect:= 0;
- END;
-
- PROCEDURE TVerticalList.SetSelection
- (newSel : LongInt);
- VAR i : LongInt;
- g : GrafPtr;
- BEGIN
- IF newSel = fSelect THEN Exit(SetSelection);
- GetPort(g);
- SetPort(fPort);
- CancelSelection;
- IF (newSel>=0) AND (newSel<=fLength) THEN BEGIN
- fSelect:= newSel;
- HiliteSelection;
- END;
- SetPort(g);
- END;
-
- PROCEDURE TVerticalList.ShowSelection;
- VAR i : LongInt;
- v : INTEGER;
- BEGIN
- IF fSelect = 0 THEN Exit(ShowSelection);
- i:= fSelect - fOffLin;
- v:= VisibleLines;
- IF (i>0) AND (i<=v) THEN Exit(ShowSelection);
- v:= v DIV 2; {Centre vertically}
- IF v = 0 THEN v:= 1;
- fOffLin:= fSelect - v;
- IF fOffLin < 0 THEN fOffLin:= 0;
- RecalOffByte;
- SetScrollValue;
- Draw;
- END;
-
- PROCEDURE TVerticalList.InitKeyStuff;
- BEGIN
- fUserHitKeys:= '';
- fLastKeyTime:= 0;
- END;
-
- PROCEDURE TVerticalList.SelectCellStart(c : CHAR);
- VAR sUser : StrListKey;
- iUser : INTEGER;
- FUNCTION NewKeyString : BOOLEAN;
- VAR x : LongInt;
- BEGIN
- x:= TickCount;
- iUser:= Length(sUser);
- IF iUser = 0 THEN NewKeyString:= TRUE
- ELSE IF iUser = listKeyLeng THEN
- NewKeyString:= TRUE
- ELSE NewKeyString:=
- (x - fLastKeyTime > GetDblTime);
- fLastKeyTime:= x;
- END;
- PROCEDURE ScanForMatch;
- VAR sList : StrListKey;
- iList, {Use a LongInt to be safe}
- i,
- lastOne,
- nextOne,
- timeHere : LongInt;
- PROCEDURE ExitSCS;
- BEGIN
- HUnLock(fData);
- {Compensate for time spent here}
- fLastKeyTime:=
- fLastKeyTime + (TickCount-timeHere);
- Exit(SelectCellStart);
- END;
- BEGIN
- timeHere:= TickCount;
- SetCursor(waitCursor^^);
- i:= fOffLin; nextOne:= fOffByt; {From top}
- HLock(fData);
- WHILE i < fLength DO BEGIN
- i:= i + 1;
- lastOne:= nextOne + 1;
- nextOne:=
- Munger(fData,lastOne,blnkPtr,1,NIL,0);
- IF nextOne < 0 THEN ExitSCS; {Error!}
- iList:= nextOne - lastOne;
- IF iList > iUser THEN iList:= iUser;
- BlockMove(Ptr(ORD(fData^)+lastOne),
- Ptr(ORD(@sList)+1),iList);
- sList[0]:= CHR(iList);
- IF IUEqualString(sList,sUser) = 0 THEN
- BEGIN
- SetSelection(i);
- ShowSelection;
- ExitSCS;
- END;
- END;
- ExitSCS;
- END;
- BEGIN
- CancelSelection;
- sUser:= fUserHitKeys;
- IF NewKeyString THEN sUser:= MakeStr1(c)
- ELSE sUser:= Concat(sUser,MakeStr1(c));
- iUser:= Length(sUser);
- fUserHitKeys:= sUser;
- ScanForMatch;
- END;
-
- FUNCTION TVerticalList.KeyIt
- (c : CHAR; modif : INTEGER) : LongInt;
- BEGIN
- IF c IN [left,right,up,down] THEN BEGIN
- KeyIt:= fItsValue;
- IF c= up THEN SetSelection(fSelect-1)
- ELSE IF c=down THEN SetSelection(fSelect+1);
- ShowSelection;
- END
- ELSE IF c IN [entr,cRet] THEN BEGIN
- ShowSelection;
- KeyIt:= MakeLongInt(fItsValue,doubleClick);
- END
- ELSE IF BAnd(modif,cmdKey) <> 0 THEN
- KeyIt:= INHERITED KeyIt(c,modif)
- ELSE IF c >= blnkChr THEN BEGIN
- KeyIt:= fItsValue;
- SelectCellStart(c);
- END
- ELSE KeyIt:= INHERITED KeyIt(c,modif);
- END;
-
- PROCEDURE TVerticalList.Response
- (theItem,theKind : INTEGER);
- VAR s : Str255;
- BEGIN
- IF theItem <> fItsValue THEN
- INHERITED Response(theItem,theKind)
- ELSE IF theKind = doubleClick THEN BEGIN
- IF (fSelect<fOffLin) OR (fSelect<=0) THEN
- SysBeep(1)
- ELSE BEGIN
- s:= GetSelection;
- s:= Concat('Entry #',
- IntString(fSelect),' is:',cRet,s);
- SetDAFont(fFont.n);
- SimpleAlert(s);
- SetDAFont(systemFont);
- END;
- END;
- END;
-
- PROCEDURE TVerticalList.Resize(hauteur : INTEGER);
- VAR r : Rect;
- g : GrafPtr;
- BEGIN
- r:= fBorder;
- fBorder.bottom:= fBorder.top + hauteur;
- IF fBorder.bottom > r.bottom THEN BEGIN
- GetPort(g);
- SetPort(fPort);
- r.top:= r.bottom;
- r.bottom:= fBorder.bottom;
- InvalRect(r);
- SetPort(g);
- END;
- SizeControl(fScroll,scrWidth+1,hauteur+2);
- CheckScrollability;
- END;
-
- {••••••••••••••••••••••••••••••••••••••••••••••••}
- { METHODS OF OBJECT TYPE “TPlainButton”. }
- {••••••••••••••••••••••••••••••••••••••••••••••••}
- PROCEDURE TPlainButton.IPlainButton
- (iBorder : Rect; iTitle : Str15;
- iEquiv : CHAR; iFont : FontIdent);
- VAR f : FontIdent;
- x : INTEGER;
- info : FontInfo;
- BEGIN
- IPDialogItem(iBorder);
- fFlag[enable]:= TRUE; {Override the default}
- fTitle:= iTitle;
- fEquiv[1]:= iEquiv;
- IF iEquiv IN ['A'..'Z'] THEN
- iEquiv:= CHR(ORD(iEquiv)+32)
- ELSE IF iEquiv IN ['a'..'z'] THEN
- iEquiv:= CHR(ORD(iEquiv)-32);
- fEquiv[2]:= iEquiv;
- fFont:= iFont;
- {If border’s height is zero, then calculate it}
- IF fBorder.top = fBorder.bottom THEN BEGIN
- GetFontIdent(f);
- SetFontIdent(iFont);
- GetFontInfo(info);
- WITH info DO x:= ascent + descent + leading;
- IF x < minBtnHeight THEN x:= minBtnHeight;
- fBorder.bottom:= fBorder.top+x+ExtraHeight;
- SetFontIdent(f);
- END;
- END;
-
- FUNCTION TPlainButton.KeyInfo : Str15;
- VAR s : Str15;
- BEGIN
- s:= ' {';
- IF fEquiv[1] = null
- THEN s:= Concat(s,'null')
- ELSE s:= Concat(s,fEquiv[1]);
- IF fEquiv[2] = null
- THEN s:= Concat(s,', null')
- ELSE s:= Concat(s,', ',fEquiv[2]);
- KeyInfo:= Concat(s,'}');
- END;
-
- FUNCTION TPlainButton.ButtonInfo : Str255;
- BEGIN ButtonInfo:= 'Plain button'; END;
-
- FUNCTION TPlainButton.Information : Str255;
- BEGIN
- Information:= Concat(ButtonInfo,KeyInfo);
- END;
-
- FUNCTION TPlainButton.ExtraHeight : INTEGER;
- BEGIN ExtraHeight:= 2; END;
- PROCEDURE TPlainButton.DrawTitle(r : Rect);
- CONST commandChar = CHR(17);
- VAR s : Str15;
- p : Point;
- info : FontInfo;
- saveFont,textFont : FontIdent;
- BEGIN
- GetFontIdent(saveFont);
- textFont:= fFont;
- SetFontIdent(textFont);
- s:= fTitle;
- GetFontInfo(info);
- p.h:= (r.left+r.right-StringWidth(s)) DIV 2;
- p.v:= info.descent;
- IF p.v < minBtnDescent THEN p.v:=minBtnDescent;
- p.v:= r.bottom - p.v;
- MoveTo(p.h,p.v);
- DrawString(s);
- IF fEquiv[1] <> null THEN BEGIN
- SetFontSizeFace(systemFont,12,[condense]);
- s:= Concat(commandChar,fEquiv[1]);
- p.h:= r.right - StringWidth(s) - 2;
- MoveTo(p.h,p.v);
- DrawString(s);
- END;
- SetFontIdent(saveFont);
- IF NOT (fFlag[active] AND fFlag[enable]) THEN
- BEGIN
- PenPat(gray);
- PenMode(patBic);
- PaintRect(r);
- PenNormal;
- END;
- END;
-
- PROCEDURE TPlainButton.Draw;
- VAR r : Rect;
- BEGIN
- GetRectangle(r);
- InsetRect(r,-1,-1);
- EraseRect(r);
- FrameRoundRect(r,ovalSize,ovalSize);
- InsetRect(r,1+ovalSize,1);
- DrawTitle(r);
- END;
-
- PROCEDURE TPlainButton.ActivateIt;
- BEGIN
- fFlag[active]:= TRUE;
- Draw;
- INHERITED ActivateIt;
- END;
-
- PROCEDURE TPlainButton.DeactivateIt;
- VAR r : Rect;
- BEGIN
- fFlag[active]:= FALSE;
- Draw;
- INHERITED DeactivateIt;
- END;
-
- FUNCTION TPlainButton.Click
- (p : Point; modif : INTEGER) : LongInt;
- VAR r : Rect;
- BEGIN
- GetRectangle(r);
- IF PtInRect(p,r) THEN BEGIN
- IF NOT (fFlag[active] AND fFlag[enable])THEN
- Click:= noItemHit
- ELSE IF MouseReleasedHere THEN
- Click:= fItsValue
- ELSE Click:= noItemHit;
- END
- ELSE IF fNexThing = NIL THEN Click:= noItemHit
- ELSE Click:= fNexThing.Click(p,modif);
- END;
-
- PROCEDURE TPlainButton.Invert(r : Rect);
- BEGIN
- BitClr(Ptr(hiliteMode),pHiliteBit);
- InvertRoundRect(r,ovalSize,ovalSize);
- END;
-
- { “MouseReleasedHere” tracks mouse in button.}
- FUNCTION TPlainButton.MouseReleasedHere : BOOLEAN;
- VAR p : Point;
- r : Rect;
- inside : MouseFlags;
- BEGIN
- GetRectangle(r);
- inside[before]:= TRUE;
- InsetRect(r,1,1);
- Invert(r);
- REPEAT
- GetMouse(p);
- inside[now]:= PtInRect(p,r);
- IF inside[now] <> inside[before] THEN BEGIN
- Invert(r);
- inside[before]:= inside[now];
- END;
- UNTIL NOT StillDown;
- MouseReleasedHere:= inside[now];
- IF inside[now] THEN Invert(r);
- END;
-
- { “VisualFeedback” is used by “KeyIt” to
- simulate a hit in the button. Somewhat
- similar to “MouseReleasedHere”. }
- PROCEDURE TPlainButton.VisualFeedback;
- VAR r : Rect;
- x : LongInt;
- BEGIN
- GetRectangle(r);
- InsetRect(r,1,1);
- Invert(r);
- Delay(feedbackDelay,x);
- Invert(r);
- END;
-
- FUNCTION TPlainButton.KeyIt
- (c : CHAR; modif : INTEGER) : LongInt;
- BEGIN
- IF c = null THEN
- KeyIt:= INHERITED KeyIt(c,modif)
- ELSE IF BAnd(modif,cmdKey) = 0 THEN
- KeyIt:= INHERITED KeyIt(c,modif)
- ELSE IF (c = fEquiv[1]) OR (c = fEquiv[2]) THEN
- BEGIN
- VisualFeedback;
- KeyIt:= fItsValue;
- END
- ELSE KeyIt:= INHERITED KeyIt(c,modif);
- END;
-
- {••••••••••••••••••••••••••••••••••••••••••••••••}
- { METHODS OF OBJECT TYPE “TToggleButton”. }
- {••••••••••••••••••••••••••••••••••••••••••••••••}
- PROCEDURE TToggleButton.IToggleButton
- (iBorder : Rect; iTitle : Str15;
- iEquiv : CHAR; iFont : FontIdent;
- iStatus : INTEGER);
- BEGIN
- IPlainButton(iBorder,iTitle,iEquiv,iFont);
- fStatus:= iStatus;
- END;
-
- FUNCTION TToggleButton.ButtonInfo : Str255;
- BEGIN
- IF fStatus = toggleOff
- THEN ButtonInfo:= 'Toggle button, now OFF'
- ELSE ButtonInfo:= 'Toggle button, now ON';
- END;
-
- FUNCTION TToggleButton.ExtraHeight : INTEGER;
- BEGIN ExtraHeight:= 4; END;
-
- PROCEDURE TToggleButton.Draw;
- VAR r : Rect;
- BEGIN
- GetRectangle(r);
- InsetRect(r,-1,-1);
- EraseRect(r);
- FrameRoundRect(r,ovalSize,ovalSize);
- InsetRect(r,2,2);
- IF fStatus = toggleOn THEN
- FrameRoundRect(r,ovalSize,ovalSize);
- InsetRect(r,1+ovalSize,1);
- DrawTitle(r);
- END;
-
- FUNCTION TToggleButton.Click
- (p : Point; modif : INTEGER) : LongInt;
- VAR result : INTEGER;
- BEGIN
- result:= INHERITED Click(p,modif);
- IF result = fItsValue THEN BEGIN
- fStatus:= toggleOn - fStatus;
- Draw;
- END;
- Click:= result;
- END;
-
- PROCEDURE TToggleButton.VisualFeedback;
- BEGIN
- INHERITED VisualFeedback;
- fStatus:= toggleOn - fStatus;
- Draw;
- END;
-
- {••••••••••••••••••••••••••••••••••••••••••••••••}
- { METHODS OF OBJECT TYPE “TThreeDButton”. }
- {••••••••••••••••••••••••••••••••••••••••••••••••}
- PROCEDURE TThreeDButton.IThreeDButton
- (iBorder : Rect; iTitle : Str15;
- iEquiv : CHAR; iFont : FontIdent);
- BEGIN
- IPlainButton(iBorder,iTitle,iEquiv,iFont);
- END;
-
- FUNCTION TThreeDButton.ButtonInfo : Str255;
- BEGIN ButtonInfo:= 'Three-dimensional button';END;
-
- FUNCTION TThreeDButton.ExtraHeight : INTEGER;
- BEGIN ExtraHeight:= 12; END;
-
- PROCEDURE TThreeDButton.FancyBorder(r : Rect;
- hilited : BOOLEAN);
- VAR i : INTEGER;
- BEGIN
- FrameRect(r);
- IF hilited THEN BEGIN
- FOR i:= 1 TO 2 DO BEGIN
- InsetRect(r,1,1);
- PenPat( gray); FrameTop(r);
- PenPat(black); FrameBot(r);
- END;
- FOR i:= 1 TO 2 DO BEGIN
- InsetRect(r,1,1);
- PenPat(black); FrameTop(r);
- PenPat( gray); FrameBot(r);
- END;
- END
- ELSE BEGIN
- PenPat(gray);
- FOR i:= 1 TO 2 DO BEGIN
- InsetRect(r,1,1);
- FrameBot(r);
- END;
- FOR i:= 1 TO 2 DO BEGIN
- InsetRect(r,1,1);
- FrameTop(r);
- END;
- END;
- PenNormal;
- InsetRect(r,1,1); FrameRect(r);
- END;
-
- PROCEDURE TThreeDButton.DropShadow(r : Rect;
- depth : INTEGER);
- BEGIN
- WHILE depth > 0 DO BEGIN
- OffsetRect(r,1,1);
- FrameBot(r);
- depth:= depth - 1;
- END;
- END;
-
- PROCEDURE TThreeDButton.Draw;
- VAR r : Rect;
- BEGIN
- GetRectangle(r);
- EraseRect(r); {Clean up first}
- FancyBorder(r,FALSE);
- DropShadow(r,shadow3Doff);
- InsetRect(r,6,6);
- DrawTitle(r);
- END;
-
- PROCEDURE TThreeDButton.PushDown(VAR r : Rect;
- depth : INTEGER);
- VAR x : LongInt;
- rgn : RgnHandle;
- BEGIN
- rgn:= NewRgn;
- WHILE depth > 0 DO BEGIN
- Delay(threeDDelay,x);
- ScrollRect(r,1,1,rgn);
- OffsetRect(r,1,1);
- depth:= depth - 1;
- END;
- DisposeRgn(rgn);
- END;
-
- PROCEDURE TThreeDButton.PopUp(VAR r : Rect;
- depth : INTEGER);
- VAR x : LongInt;
- rgn : RgnHandle;
- BEGIN
- rgn:= NewRgn;
- WHILE depth > 0 DO BEGIN
- Delay(threeDDelay,x);
- ScrollRect(r,-1,-1,rgn);
- FrameBot(r);
- OffsetRect(r,-1,-1);
- FrameTop(r);
- depth:= depth - 1;
- END;
- DisposeRgn(rgn);
- END;
-
- FUNCTION TThreeDButton.MouseReleasedHere:BOOLEAN;
- VAR p : Point;
- r : Rect;
- inside : MouseFlags;
- BEGIN
- GetRectangle(r);
- inside[before]:= TRUE;
- PushDown(r,shadow3Doff);
- REPEAT
- GetMouse(p);
- inside[now]:= PtInRect(p,r);
- IF inside[now] <> inside[before] THEN BEGIN
- IF inside[before]
- THEN PopUp(r,shadow3Doff)
- ELSE PushDown(r,shadow3Doff);
- inside[before]:= inside[now];
- END;
- UNTIL NOT StillDown;
- MouseReleasedHere:= inside[now];
- IF inside[now] THEN PopUp(r,shadow3Doff);
- END;
-
- PROCEDURE TThreeDButton.VisualFeedback;
- VAR r : Rect;
- x : LongInt;
- BEGIN
- GetRectangle(r);
- PushDown(r,shadow3Doff);
- Delay(feedbackDelay,x);
- PopUp(r,shadow3Doff);
- END;
-
- {••••••••••••••••••••••••••••••••••••••••••••••••}
- { METHODS OF OBJECT TYPE “TToggl3DButton”. }
- {••••••••••••••••••••••••••••••••••••••••••••••••}
- PROCEDURE TToggl3DButton.IToggl3DButton
- (iBorder : Rect;
- iTitle : Str15;
- iEquiv : CHAR;
- iFont : FontIdent;
- iStatus : INTEGER);
- BEGIN
- IPlainButton(iBorder,iTitle,iEquiv,iFont);
- fStatus:= iStatus;
- END;
-
- FUNCTION TToggl3DButton.ButtonInfo : Str255;
- VAR s : String[3];
- BEGIN
- IF fStatus = toggleOff THEN s:= 'OFF'
- ELSE s:= 'ON';
- ButtonInfo:= Concat(
- 'Three-dimensional toggle button, now ',s);
- END;
-
- PROCEDURE TToggl3DButton.Draw;
- VAR r : Rect;
- BEGIN
- IF fStatus = toggleOff THEN INHERITED Draw
- ELSE BEGIN
- GetRectangle(r);
- EraseRect(r);
- OffsetRect(r,shadow3Ddiff,shadow3Ddiff);
- FancyBorder(r,TRUE);
- DropShadow(r,shadow3Don);
- InsetRect(r,6,6);
- DrawTitle(r);
- END;
- END;
-
- FUNCTION TToggl3DButton.MouseReleasedHere:BOOLEAN;
- VAR r : Rect;
- inside : MouseFlags;
- PROCEDURE LocalTrackMouse(oldHeight,
- toggledHeight : INTEGER);
- VAR p : Point;
- BEGIN
- PushDown(r,oldHeight);
- REPEAT
- GetMouse(p);
- inside[now]:= PtInRect(p,r);
- IF inside[now] <> inside[before] THEN
- BEGIN
- IF inside[before]
- THEN PopUp(r,oldHeight)
- ELSE PushDown(r,oldHeight);
- inside[before]:= inside[now];
- END;
- UNTIL NOT StillDown;
- IF inside[now] THEN PopUp(r,toggledHeight);
- END;
- BEGIN
- GetRectangle(r);
- inside[before]:= TRUE;
- IF fStatus = toggleOff THEN
- LocalTrackMouse(shadow3Doff,shadow3Don)
- ELSE BEGIN
- OffsetRect(r,shadow3Ddiff,shadow3Ddiff);
- LocalTrackMouse(shadow3Don,shadow3Doff);
- END;
- MouseReleasedHere:= inside[now];
- END;
-
- FUNCTION TToggl3DButton.Click
- (p : Point; modif : INTEGER) : LongInt;
- VAR result : INTEGER;
- BEGIN
- result:= INHERITED Click(p,modif);
- IF result = fItsValue THEN BEGIN
- fStatus:= toggleOn - fStatus;
- Draw;
- END;
- Click:= result;
- END;
-
- PROCEDURE TToggl3DButton.VisualFeedback;
- VAR r : Rect;
- x : LongInt;
- BEGIN
- GetRectangle(r);
- IF fStatus = toggleOff THEN BEGIN
- PushDown(r,shadow3Doff);
- Delay(feedbackDelay,x);
- PopUp(r,shadow3Don);
- END
- ELSE BEGIN
- OffsetRect(r,shadow3Ddiff,shadow3Ddiff);
- PushDown(r,shadow3Don);
- Delay(feedbackDelay,x);
- PopUp(r,shadow3Doff);
- END;
- fStatus:= toggleOn - fStatus;
- Draw;
- END;
-
- {••••••••••••••••••••••••••••••••••••••••••••••••}
- { METHODS OF OBJECT TYPE “TIcon”. }
- {••••••••••••••••••••••••••••••••••••••••••••••••}
- PROCEDURE TIcon.IIcon(iBorder : Rect;
- iIconID : INTEGER);
- BEGIN
- WITH iBorder DO BEGIN
- right:= left + 32;
- bottom:= top + 32;
- END;
- IPDialogItem(iBorder);
- fIconID:= iIconID;
- END;
-
- FUNCTION TIcon.Information : Str255;
- VAR s : Str255;
- BEGIN
- s:= Concat('Icon, resource id = ',
- IntString(fIconID),', ');
- IF fFlag[enable]
- THEN s:= Concat(s,'now visible')
- ELSE s:= Concat(s,'now invisible');
- Information:= s;
- END;
-
- { “fFlag[enable]” controls showing/hiding. }
- PROCEDURE TIcon.Draw;
- VAR r : Rect;
- h : Handle;
- BEGIN
- GetRectangle(r);
- IF fFlag[enable] THEN BEGIN
- h:= GetResource('ICN#',fIconID);
- IF h <> NIL THEN PlotIcon(r,h);
- END
- ELSE EraseRect(r);
- END;
-
- {••••••••••••••••••••••••••••••••••••••••••••••••}
- { METHODS OF OBJECT TYPE “TAnimation”. }
- {••••••••••••••••••••••••••••••••••••••••••••••••}
- PROCEDURE TAnimation.IAnimation(iBorder:Rect;
- iBaseID:INTEGER;
- iNumber:INTEGER);
- BEGIN
- IPDialogItem(iBorder);
- fFlag[enable]:= TRUE; {Override the default}
- fBaseID := iBaseID;
- fNumber := iNumber;
- fCurrent:= 1;
- fForward:= TRUE;
- fLastTim:= 0;
- END;
-
- FUNCTION TAnimation.Information : Str255;
- VAR s : Str255;
- BEGIN
- IF fFlag[animate] THEN s:= 'Animation ON, '
- ELSE s:= 'Animation OFF, ';
- s:= Concat(s,'currently #',
- IntString(fCurrent),' of ');
- s:= Concat(s,IntString(fNumber),' frames.');
- Information:= s;
- END;
-
- PROCEDURE TAnimation.NextFrame;
- BEGIN
- IF fForward THEN BEGIN
- fCurrent:= fCurrent + 1;
- IF fCurrent > fNumber THEN BEGIN
- fCurrent:= fNumber;
- fForward:= FALSE;
- END;
- END
- ELSE BEGIN
- fCurrent:= fCurrent - 1;
- IF fCurrent < 1 THEN BEGIN
- fCurrent:= 1;
- fForward:= TRUE;
- END;
- END;
- END;
-
- PROCEDURE TAnimation.Idle;
- VAR x : LongInt;
- BEGIN
- IF fFlag[animate] THEN BEGIN
- x:= TickCount;
- IF x - fLastTim >= animThreshold THEN BEGIN
- NextFrame;
- Draw;
- fLastTim:= x;
- END;
- END;
- INHERITED Idle;
- END;
-
- { “TAnimation.Draw” draws the picture
- horizontally centred in and at bottom of "r".}
- PROCEDURE TAnimation.Draw;
- VAR p : PicHandle;
- x,y : INTEGER;
- r,rPic : Rect;
- BEGIN
- GetRectangle(r);
- EraseRect(r);
- p:= GetPicture(fBaseID+fCurrent);
- IF p = NIL THEN Exit(Draw);
- rPic:= p^^.picFrame;
- WITH r DO x:= (left + right) DIV 2;
- WITH rPic DO x:= x - ((left + right) DIV 2);
- y:= r.bottom - rPic.bottom;
- OffsetRect(rPic,x,y);
- DrawPicture(p,rPic);
- END;
-
- {••••••••••••••••••••••••••••••••••••••••••••••••}
- { METHODS OF OBJECT TYPE “TStaticText” }
- {••••••••••••••••••••••••••••••••••••••••••••••••}
- PROCEDURE TStaticText.IStaticText
- (iBorder : Rect; iFont : FontIdent;
- iContents : Str255);
- BEGIN
- IPDialogItem(iBorder);
- fFlag[enable]:= TRUE; {Override the default}
- fFont:= iFont;
- fContents:= iContents;
- END;
-
- FUNCTION TStaticText.Information : Str255;
- VAR s : Str255;
- BEGIN
- s:= fContents;
- s:= IntString(Length(s));
- Information:=
- Concat('Static text item of length ',s);
- END;
-
- PROCEDURE TStaticText.DrawBorder;
- VAR r : Rect;
- BEGIN
- GetRectangle(r);
- IF fFlag[active] THEN FrameRect(r)
- ELSE BEGIN
- PenPat(gray);
- FrameRect(r);
- PenPat(black);
- END;
- END;
-
- PROCEDURE TStaticText.Draw;
- VAR s : Str255;
- r : Rect;
- saveFont,
- textFont : FontIdent;
- BEGIN
- DrawBorder;
- s:= fContents;
- GetFontIdent(saveFont);
- textFont:= fFont;
- SetFontIdent(textFont);
- GetRectangle(r);
- InsetRect(r,1,1);
- TextBox(Ptr(ORD(@s)+1),Length(s),r,
- teJustCenter);
- SetFontIdent(saveFont);
- END;
-
- PROCEDURE TStaticText.ActivateIt;
- BEGIN
- fFlag[active]:= TRUE;
- DrawBorder;
- INHERITED ActivateIt;
- END;
-
- PROCEDURE TStaticText.DeactivateIt;
- BEGIN
- fFlag[active]:= FALSE;
- DrawBorder;
- INHERITED DeactivateIt;
- END;
-
- END.
-